package cc.aliza.lib.mongo.core.listener;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.TimeUnit;

/**
 * 『给时光以生命·给岁月以文明』
 *
 * @author Zhang Jing (byrdkm17@gmail.com).
 */
public class AlizaFramework {

    private ExecutorService service = null;

    private AlizaFramework() {
        int size = Runtime.getRuntime().availableProcessors() * 2 + 1;
        service = Executors.newFixedThreadPool(size);
    }

    public static AlizaFramework getInstance() {
        return Holder.instance;
    }

    public ExecutorService getService() {
        return service;
    }

    public void destroy() {
        if (service != null) {
            service.shutdown();

            try {
                if (service.awaitTermination(30, TimeUnit.SECONDS)) {
                    service.shutdownNow();
                }
            } catch (InterruptedException ignored) {

            }
        }
    }

    private static class Holder {
        static final AlizaFramework instance = new AlizaFramework();
    }

}
